package com.atguigu.gulimail.order.service.impl;

import com.atguigu.gulimail.order.entity.OrderEntity;
import com.atguigu.gulimail.order.entity.OrderReturnReasonEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimail.order.dao.OrderItemDao;
import com.atguigu.gulimail.order.entity.OrderItemEntity;
import com.atguigu.gulimail.order.service.OrderItemService;


@Service("orderItemService")
//@RabbitListener(queues = {"hello-java-queue"})
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );

        return new PageUtils(page);
    }

//    /**
//     * queues:声明需要监听的所有队列
//     */
////    @RabbitListener(queues = {"hello-java-queue"})
//    @RabbitHandler
//    public void receiveMessage(Message message, OrderReturnReasonEntity content,
//                               Channel channel) {
//        byte[] body = message.getBody();
//        MessageProperties properties = message.getMessageProperties();
//        System.out.println("接收到消息...");
////        System.out.println("接收到消息...内容" + message + "==>内容：" + content);
//        // 签收货物，非批量模式
//        try {
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//    @RabbitHandler
//    public void receiveMessage1(Message message, OrderEntity content,
//                               Channel channel) {
//        byte[] body = message.getBody();
//        MessageProperties properties = message.getMessageProperties();
//        System.out.println("接收到消息...");
////        System.out.println("接收到消息...内容" + message + "==>内容：" + content);
//    }

}